(function() {
    "use strict";
    angular
        .module("codeVerificationSystem")
        .controller("SubmissionListController",
        [
            "$http",
            "submissionResource",
            "$uibModalInstance",
            "task",
            SubmissionListController
        ]);

    function SubmissionListController($http, submissionResource, $uibModalInstance, task) {
        var vm = this;

        vm.cancel = function () {
            $uibModalInstance.dismiss();
        };

        submissionResource.query({ id: task.id }, function(data) {
            vm.submissions = data;
            if (vm.submissions != null && vm.submissions.length > 0) {
                vm.viewSubmissionDetails(vm.submissions[0].id);
                vm.activeSubmissionId = vm.submissions[0].id;
            }
        });

        vm.submissionDetailsEnabled = true;
        vm.viewSubmissionDetails = function (submissionsId) {
            vm.activeSubmissionId = submissionsId;
            $http({
                method: "GET",
                url: "http://localhost:49616/api/submissions/" + submissionsId,
                headers: {
                    'Content-Type': "application/json; charset=utf-8"
                }
            }).then(function successCallback(response) {
                vm.submissionDetails = response.data;
            }, function errorCallback(response) {
                console.log("losho");
            });
        };


    }
}());
